package com.comac.tasks.manager.app.command;

import com.alibaba.cola.dto.Response;
import com.alibaba.cola.exception.BizException;
import com.comac.mom.simpleintegration.mq.MQProducerComponent;
import com.comac.tasks.manager.app.dto.TasksManagerBatchInsertDTO;
import com.comac.tasks.manager.app.mq.listener.TasksManagerInsertListener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * 更新执行
 *
 * @author wfb
 * @date 2021年12月16日11:48:43
 */
@Component
@Slf4j
public class TasksManagerBatchInsertExe {
    @Resource
    private MQProducerComponent mqProducerComponent;

    public Response execute(TasksManagerBatchInsertDTO batchInsertDTO) {
        try {
            Component component = TasksManagerInsertListener.class.getAnnotation(Component.class);
            String topic = component.value();
            mqProducerComponent.sendMsg(topic, "tasks_tag", batchInsertDTO, Boolean.TRUE);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("sendMsg error msg:" + e.toString());
            log.error("sendMsg stackTrace:" + Arrays.toString(e.getStackTrace()));
            throw new BizException("批量新增代码消息sendMsg发送失败:内部异常" + e.toString());
        } catch (Throwable th) {
            throw new BizException("批量新增代码消息sendMsg发送失败:内部错误" + th.toString());
        }
        return Response.buildSuccess();
    }

}
